﻿using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class U3DResourcesMgr
{
    private static Dictionary<string, Object> m_Res = new Dictionary<string, Object>();
    private static List<AudioClip> m_aHitBallSound = new List<AudioClip>();
    private static List<AudioClip> m_aTiaoJiao = new List<AudioClip>();

    public static AudioClip RandomHitBallSound
    {
        get
        {
            int index = Random.Range(0, m_aHitBallSound.Count);
            return m_aHitBallSound[index];
        }
    }

    public static AudioClip RandomTiaoJiaoSound
    {
        get
        {
            int index = Random.Range(0, m_aTiaoJiao.Count);
            return m_aTiaoJiao[index];
        }
    }

    public static void Init()
    {
        string path = "Audio/HitBall";
        var objects = Resources.LoadAll(path);
        foreach (var o in objects)
        {
            m_Res.Add(path + "/" + o.name, o);
            m_aHitBallSound.Add(o as AudioClip);
        }

        path = "Audio/TiaoJiao";
        objects = Resources.LoadAll(path);
        foreach (var o in objects)
        {
            m_Res.Add(path + "/" + o.name, o);
            m_aTiaoJiao.Add(o as AudioClip);
        }
    }

    public static Object LoadRes(string res)
    {
        if (!m_Res.ContainsKey(res))
        {
            var o = Resources.Load(res);
            if (o == null)
            {
                Debug.Log("Can not find res " + res);
                return null;
            }
            m_Res.Add(res, o);
        }

        return m_Res[res];
    }
}
